Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Linux DRM backend #69

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Support Linux DRM backend #69

wants to merge 2 commits into from

Conversation

Bennctu
Copy link
Collaborator

@Bennctu Bennctu commented Nov 3, 2024

Currently, using the DRM legacy interface is suitable for Mado's backend because we only need basic window display without advanced features.

backend/drm.c Outdated Show resolved Hide resolved
backend/drm.c Outdated Show resolved Hide resolved
@jserv
Copy link
Contributor

jserv commented Nov 3, 2024

Currently, using the DRM legacy interface is suitable for Mado's backend because we only need basic window display without advanced features.

What compatibility risks exist when using DRM legacy interfaces with newer Linux kernels? Could you verify the compatibility status of libdrm across different kernel versions?

What prevents the DRM backend from rendering content across the full screen resolution?

@jserv
Copy link
Contributor

jserv commented Nov 3, 2024

@a1091150, You might check DRM backend for your environment as well.

Makefile Show resolved Hide resolved

return true;

bail_crtc:
Copy link

@p96114175 p96114175 Nov 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused about this. It should be as below.

/* Retrieve resources */
if (!get_resources(tx->drm_dri_fd, &RES(tx)))
    goto bail_res;
....
bail_fb:
    drmModeRmFB(tx->drm_dri_fd, tx->fb_id);
    munmap(tx->fb_base, tx->fb_len);
bail_crtc:
    drmModeFreeCrtc(CRTC(tx));
bail_conn:
    drmModeFreeConnector(CONN(tx));
bail_res:
    drmModeFreeResources(RES(tx));

Copy link
Contributor

@jserv jserv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rebase the latest main branch and resolve conflicts.

Implemented DRM-based framebuffer setup, including:
 - Opening DRM device
 - Creating dumb buffers and mapping them to framebuffers
 - Setting mode and handling CRTC for connected display output

Currently, using the DRM legacy interface is suitable for Mado's backend
if we only need basic window display without advanced features. The DRM
legacy is simpler to implement.

Close sysprog21#60
@@ -83,6 +83,9 @@ For SDL backend, install the [SDL2 library](https://www.libsdl.org/).
* macOS: `brew install sdl2`
* Ubuntu Linux / Debian: `sudo apt install libsdl2-dev`

For DRM backend, install the [libdrm](https://cgit.freedesktop.org/mesa/drm/).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the hyperlink to https://gitlab.freedesktop.org/mesa/drm

@@ -0,0 +1,24 @@
/*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decouple linux VT changes in another pull request which adapts fbdev backend as well. That is, the linux VT routines should be shared between fbdev and DRM backends.

@Bennctu
Copy link
Collaborator Author

Bennctu commented Nov 6, 2024

Currently, using the DRM legacy interface is suitable for Mado's backend because we only need basic window display without advanced features.

What compatibility risks exist when using DRM legacy interfaces with newer Linux kernels? Could you verify the compatibility status of libdrm across different kernel versions?

What prevents the DRM backend from rendering content across the full screen resolution?

I need more time to research and adjust.

return false;
}

/* Virtual terminal part is same as fbdev */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decouple this to another pull request to share the Linux VT manipulation.

{
*resources = drmModeGetResources(fd);
if (*resources == NULL) {
log_error("drmModeGetResources failed");
Copy link
Contributor

@jserv jserv Nov 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make the error messages consistent, starting with "Failed to ..."

@@ -12,6 +12,10 @@ config BACKEND_FBDEV
bool "Linux framebuffer support"
select CURSOR

config BACKEND_DRM
bool "DRM support"
Copy link
Collaborator

@shengwen-tw shengwen-tw Nov 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider changing to Linux DRM support for avoiding confusion.

uint32_t fb_id;
uint32_t *fb_base;
size_t fb_len;
// int display_width;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leave no dead code.

twin_coord_t width = right - left;
int line_length = 4 * tx->width;
off_t off = line_length * top + 4 * left;
unsigned char *dest = (unsigned char *) tx->fb_base + off;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace unsigned char with uint8_t for consistency and use uintptr_t for pointer arithmetic. That is:

uint8_t *dest = (uint8_t *)((uintptr_t) tx->fb_base + off);

return NULL;
}


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove one empty line here.

free(ctx->priv);
free(ctx);
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

@jserv
Copy link
Contributor

jserv commented Nov 11, 2024

Check the DRM implementation for reference: https://github.com/zlgopen/awtk-linux-fb/blob/master/awtk-port/lcd_linux/lcd_linux_drm.c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants